package cn.wolfcode.trip.base.domain;

import com.alibaba.druid.support.json.JSONUtils;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
import org.springframework.format.annotation.DateTimeFormat;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;

/**
 * 游记推荐
 */
@ToString
@Getter
@Setter
public class TravelCommend {
    public static final int TYPE_WEEK = 1; // 每周推荐
    public static final int TYPE_MONTH = 2; // 每月推荐
    public static final int TYPE_STRATEGY = 3; // 攻略推荐
    private Long id;
    // 关联的游记
    private Travel travel;
    //标题
    private String title;
    //副标题
    private String subTitle;
    //封面url
    private String coverUrl;
    // 推荐时间安排
    @DateTimeFormat(pattern = "yyyy-MM-dd") // 保存时格式化时间
    private Date schedule;
    //推荐类型
    private Integer type;

    public String getTypeName() {
        String tempString = "";
        switch (type) {
            case TYPE_WEEK:
                tempString = "每周推荐";
                break;
            case TYPE_MONTH:
                tempString = "每月推荐";
                break;
            case TYPE_STRATEGY:
                tempString = "攻略推荐";
                break;
        }
        return tempString;
    }

    public String getJson() {
        HashMap<String, Object> map = new HashMap();
        map.put("id", id);
        map.put("title", title);
        map.put("travelId", travel.getId());
        map.put("subTitle", subTitle);
        map.put("coverUrl", coverUrl);
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
        String formatData = simpleDateFormat.format(schedule);
        map.put("schedule", formatData);
        map.put("type", type);
        return JSONUtils.toJSONString(map);
    }
}